package com.sprinboot_vue.blog_springboot.result;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Thomas
 * @version 1.0
 * @date 2021/11/20 21:02
 */
@Data
public class Result {
    //返回成功或者失败
    private boolean status;
    //返回状态码
    private String code;
    //返回信息
    private String message;
    //返回数据
    private Map<String,Object> map=new HashMap<>();
    //编写成功与失败的静态方法  类名.方法名产生对象
    public static Result success(){
        Result result=new Result();
        result.status=true;
        return result;
    }
    public static Result error(){
        Result result=new Result();
        result.status=false;
        return result;
    }
    //为了使用链式法则
    public Result code(String code){
        this.code=code;
        return this;
    }

    public Result message(String message){
        this.message=message;
        return this;
    }

    public Result codeAndmessage(String code,String message){
        this.code=code;
        this.message=message;
        return this;
    }

    //重载一下
    public Result codeAndmessage(ResultInfo resultInfo){
        this.code=resultInfo.getCode();
        this.message=resultInfo.getMessage();
        return this;
    }

    public Result date(String key,Object value){
        this.map.put(key,value);
        return this;
    }
}
